﻿using OABLL;
using OAModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyOA
{
    
    public partial class 请假管理 : Form
    {
        qingjiabll bll = new qingjiabll();

        public string _yuangongid = string.Empty;
        public 请假管理(string oa)
        {
            InitializeComponent();
            this._yuangongid=oa;
            
        }



        //页面加载时出现数据
        private void 请假管理_Load(object sender, EventArgs e)
        {
            List<QijiaEntity> list = bll.Getyhxinxi(_yuangongid);

            for (int i = 0; i < list.Count; i++)
            {
                QijiaEntity user = list[i];  
                ListViewItem item = new ListViewItem();
                item.Text = user.Oa员工id;
                item.SubItems.Add(user.Oa员工姓名);
                item.SubItems.Add(user.Oa请假单号);
                
                item.SubItems.Add(user.Oa请假理由);
                item.SubItems.Add(user.Oa请假时长);
                item.SubItems.Add((user.Oa请假时间.ToString()));
                string str = "";
                if (user.Oa状态.ToString() == "0") {

                    str = "待审核";
                } else if (user.Oa状态.ToString() == "1") {
                    str = "审核通过";
                }
                else {
                    str = "审核不通过";
                }

                item.SubItems.Add(str);
                //把封装好的数据添加到每一行 
                this.listView1.Items.Add(item);
            }
        }


        //添加申请
        private void button1_Click(object sender, EventArgs e)
        {
            //new QingJiaGuanLi(_yuangongid).Show();
            QingJiaGuanLi f = new QingJiaGuanLi(_yuangongid);

            f.OnSave += new QingJiaGuanLi.Save(f_OnSave);//定阅这个事件

            f.Show();

        }

        void f_OnSave()
        {
            ShuaXin();//在这个方法里执行你要刷新的操作
        }


        //删除申请
        private void button2_Click(object sender, EventArgs e)
        {
           
                if (this.listView1.SelectedItems.Count > 0)
            {

                if (MessageBox.Show("确认要删除吗?", "删除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {

                    string Oa请假单号 = this.listView1.SelectedItems[0].SubItems[2].Text.Trim();

                    if (bll.Dropshengqi(Oa请假单号)) {

                    foreach (ListViewItem item in this.listView1.SelectedItems)
                    {
                        this.listView1.Items.RemoveAt(item.Index);
                    }
                  }
                    else
                    {
                            MessageBox.Show("删除失败，请稍后重试！");
                    }
                    
              


                }
            }
            else
            {
                MessageBox.Show("请选择数据");
            }

        }




        //修改申请
        private void button3_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {

                string Oa请假单号 = this.listView1.SelectedItems[0].SubItems[2].Text.Trim();

                new zcsq(Oa请假单号,  _yuangongid).Show();
            }
            else
            {
                MessageBox.Show("请选择数据");
            }
        }




        //刷新申请
        private void button4_Click(object sender, EventArgs e)
        {
            ShuaXin();

        }

         void ShuaXin()
        {
            List<QijiaEntity> list = new List<QijiaEntity>();
            list = bll.Getyhxinxi(_yuangongid);
            listView1.Items.Clear();
            foreach (QijiaEntity user in list)
            {
                ListViewItem item = new ListViewItem();

                item.Text = user.Oa员工id;
                item.SubItems.Add(user.Oa员工姓名);
                item.SubItems.Add(user.Oa请假单号);

                item.SubItems.Add(user.Oa请假理由);
                item.SubItems.Add(user.Oa请假时长);
                item.SubItems.Add((user.Oa请假时间.ToString()));
                string str = "";
                if (user.Oa状态.ToString() == "0")
                {

                    str = "待审核";
                }
                else if (user.Oa状态.ToString() == "1")
                {
                    str = "审核通过";
                }
                else
                {
                    str = "审核不通过";
                }

                item.SubItems.Add(str);

                //把封装好的数据添加到每一行 
                this.listView1.Items.Add(item);

            }
        }
    }
    }

